package cn.lg.soar.general.client;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.general.api.constant.ModuleConst;
import cn.lg.soar.general.api.model.RegionDTO;
import cn.lg.soar.general.api.service.IRegionApi;
import cn.lg.soar.general.entity.Region;
import cn.lg.soar.general.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author luguoxiang
 * @date 2022/1/16
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ApiIgnore
@ApiClient("boot")
@RestController
@RequestMapping(ModuleConst.CLIENT_PATH + "/region")
public class RegionApiClient implements IRegionApi {

    @Autowired
    private IRegionService service;

    public final static BeanCopier<Region, RegionDTO> FROM_ENTITY = BeanCopier.create(Region.class, RegionDTO.class);

    @GetMapping("getById")
    @Override
    public RegionDTO getById(@RequestParam("id") int id) {
        return FROM_ENTITY.convert(service.getById(id));
    }

    @GetMapping("listByIds")
    @Override
    public List<RegionDTO> listByIds(@RequestParam("ids") Collection<Integer> ids) {
        return FROM_ENTITY.convertBatch(
                service.listByIds(ids)
        ).collect(Collectors.toList());
    }

    @GetMapping("getRegionPath")
    @Override
    public List<RegionDTO> getRegionPath(@RequestParam("id") int id) {
        return FROM_ENTITY.convertBatch(
                service.getRegionPath(id)
        ).collect(Collectors.toList());
    }

    @GetMapping("getNameList")
    @Override
    public List<String> getNameList(@RequestParam("id") int id) {
        return service.getNameList(id);
    }

    @GetMapping("getNameListMap")
    @Override
    public Map<Integer, List<String>> getNameListMap(@RequestParam("ids") Collection<Integer> ids) {
        return service.getNameListMap(ids);
    }
}
